﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Net.Mail;
using System.Configuration;
using System.Net.Configuration;
using System.Web.Configuration;

public partial class SiteMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {        
        SmtpSection cfg = NetSectionGroup.GetSectionGroup(WebConfigurationManager.OpenWebConfiguration("~/web.config")).MailSettings.Smtp;
        MailMessage mail = new MailMessage(cfg.From, "wangf0228@163.com");
        mail.IsBodyHtml = true;
        mail.Subject = "邮件主题，通过指定email.SubjectEncoding属性设置邮件主题的编码";
        mail.Body = "要发送的邮件内容，上面已经设置可以支持html内容，例外还可以通过指定email.BodyEncoding属性设置邮件内容的编码";
        SmtpClient smtp = new SmtpClient(cfg.Network.Host);
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = new System.Net.NetworkCredential(cfg.Network.UserName, cfg.Network.Password);
        smtp.Send(mail);
    }
}
